package com.twu.biblioteca.commands;

import com.twu.biblioteca.UserQueryHandler;
import com.twu.biblioteca.data_structures.Library;

import java.io.PrintStream;

public class LoginCommand implements Command {
    private Library library;
    private UserQueryHandler query;
    private PrintStream ps;

    public LoginCommand(Library library, UserQueryHandler query, PrintStream ps){
        this.library=library;
        this.query=query;
        this.ps=ps;
    }

    @Override
    public void run() {
        String username = query.userForString("Please enter your username");
        String password = query.userForString("Please enter your password");
        boolean isSuccessful = library.attemptLogin(username,password);
        if(isSuccessful)
            ps.println("Login successful!");
        else
            ps.println("Login failed");
        return;
    }
}
